//维护一个温度不递增的栈
//栈内存储的是对应温度的下标
class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        int n = temperatures.size();
        vector<int> ret(n, 0);  
        stack<int> index;

        for (int i = 0; i < n; i++)
        {
            while (!index.empty() && temperatures[index.top()] < temperatures[i])
            {
                int index_top = index.top();
                ret[index_top] = i - index_top;
                index.pop();
            }

            index.push(i);
        }

        return ret;
    }
};